The custom data subscriptions are typically used when the underlying data source has some kind of subscription mechanism, and you would like to use it for performance and data accuracy reasons, instead of using the default "data polling" mechanism (as described in Data Provision And Consumption Models). OPC Wizard allows you to override the data subscription behavior, and replace it by your own.
In order to take over the data subscriptions mechanism for a certain data variable, you should first set its UseDataPolling Property to false. This turns off the data polling algorithm provided by the OPC Wizard for this data variable. You then become responsible for handling the data subscriptions to this data variable.
Each data subscription (there can be multiple data subscriptions to the same data variable) is represented by an internal OPC Wizard object with IUADataSubscription Interface. The OPC Wizard creates and removes these data subscription objects for you. The OPC Wizard maintains a current set of data subscriptions on a data variable in its DataSubscriptionSet Property. Whenever a data subscription is added, modified, or removed, an OnDataSubscriptionChanged Method is called that you can override, and consequently the DataSubscriptionChanged Event is also raised. This works analogically to other requests described in Data Provision And Consumption Models, i.e. the request propagates (bubbles) to parent levels and can also be handled there, you can choose between handling the event or overriding the method, etc.
The argument passed to the OnDataSubscriptionChanged Method or the DataSubscriptionChanged Event is an instance of UADataSubscriptionChangedEventArgs Class. The member that distinguishes how the data subscription set has changed is the Action Property. Depending on its value, your code will do different things:
The data subscription object implements the ISink<UAAttributeData> Interface, which you use to provide updated data to the data subscription, by calling its OnNext Method, with an instance of UAAttributeData Class that contains the new data. There are also extension method overloads for the OnNext method; the extension methods allow you to simplify the code in cases when you just want to construct a "Good" attribute data with given value and current time as a timestamp, or to construct the attribute with specific status code, etc.
The data subscription has a State Property, which can hold a reference to any object. You can use it to associate your own data with the data subscription.
Your code is responsible for supplying the new data to the data variable when the data changes, in accordance with the SamplingInterval Property of the data subscription. This needs to be done for each of the data subscriptions that currently exist on the data variable. Note that since the data subscriptions may have different sampling intervals, the update mechanism needs to be able to supply data to each of them based on their own schedule. This can be achieved by treating each data subscription completely separately, or (in an advanced scenario) by devising an optimization algorithm to merge the subscriptions, but also properly handle their updates.
The example below illustrates how a custom data subscription can be implemented.